package uform.model.generator;

class BaseInfoExtractor
{       
	public var definitions(default, null) : Hash<FieldInfo<Dynamic>>;
	public function new()
	{
		definitions = new Hash();
	}

	public function merge(other : Hash<FieldInfo<Dynamic>>)
	{
		for(field in other.keys())
		{
			if(definitions.exists(field))
				_mergeField(definitions.get(field), other.get(field));
			else
				definitions.set(field, other.get(field));
		}
	}
	
	static function _mergeField(dest : FieldInfo<Dynamic>, src : FieldInfo<Dynamic>) 
	{
		if(null == dest.fieldType)
			dest.fieldType = src.fieldType;
		if(null == dest.defaultValue)
			dest.defaultValue = src.defaultValue;
		if(null != src.granularity)
			dest.granularity = src.granularity;
		if(null != src.weight)
			dest.weight = src.weight;
		if(null == dest.label)
			dest.label = src.label;
		if(null == dest.min)
			dest.min = src.min;
		if(null == dest.max)
			dest.max = src.max; 
	}
}